package top.kaoshanji.r1ch04a;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.util.FileCopyUtils;

import java.io.IOException;

/**
 * 代码清单-r1ch04a-88页a：指定文件编码
 * @author kaoshanji
 * ^_^
 * create time 2025/5/5 17:49
 */
public class EncodedResourceExample {

    public static void main(String[] args) throws IOException {
        Resource res = new ClassPathResource("r1ch04a/file1.txt");
        EncodedResource encRes = new EncodedResource(res, "UTF-8");

        String context = FileCopyUtils.copyToString(encRes.getReader());

        System.out.println(context);
    }

}
